<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //封装成函数 函数参数为传入的字符串
    //返回值为对象结构
    
    // var searchStr = "?id=10&page=12";
    // searchStr = searchStr.slice(1);//去？
    // var arr = searchStr.split("&");//变成数组
    // var obj = {};
    // for(var i = 0;i<arr.length;i++){
    //     var childArr = arr[i].split("=");//属性和属性值
    //     obj[childArr[0]] = childArr[1];
    // }
    // console.log(obj);
    var searchStr = "?id=10&page=12";
    function searchStr1(searchStr){
        searchStr = searchStr.slice(1);//去？
        var arr = searchStr.split("&");//变成数组
        var obj = {};
        for(var i = 0;i<arr.length;i++){
            var childArr = arr[i].split("=");//属性和属性值
            obj[childArr[0]] = childArr[1];
        }
        return obj;
    }
    var obj = searchStr1(searchStr);  
    console.log(obj);
</script>
</html>